﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SourceControlEssentials
{
    public class Suprunenko : IStudent
    {
        private string firstName;
        private string lastName;
        private int groupNumber;
        private string methodName;

        public Suprunenko()
        {
            firstName = "Vlad";
            lastName = "Suprunenko";
            groupNumber = 318;
            methodName = "Find anagrams";
        }

        public override int GetHashCode()
        {
            return firstName.GetHashCode() * lastName.GetHashCode() * groupNumber / 18;
        }

        public int Id()
        {
            return GetHashCode();
        }

        public string GetLastName()
        {
            return lastName;
        }

        public string GetFirstName()
        {
            return firstName;
        }

        public int GetGroup()
        {
            return groupNumber;
        }

        public string MethodName()
        {
            return methodName;
        }

        public string ExecuteStrategy(string value)
        {
            //find anagrams
            string result = "";
            bool condition = true;
            string[] words = value.Split(' ');
            for (int i = 0; i < words.Length; i++)
                for (int k = i + 1; k < words.Length; k++)
                    if (words[i].Length == words[k].Length)
                    {
                        for (int c = 0; c < words[i].Length; c++)
                            if (!words[i].Contains(words[k].ToCharArray()[c]))
                                condition = false;
                        if (condition)
                            result = words[i] + " " + words[k] + " ";
                        condition = true;
                    }
            if (!result.Equals(""))
                return result;
            throw new ApplicationException("\nno anagrams in the string\n");
        }

    }
}
